#include <iostream>
#include <string>
#include <fmt/format.h>
#include <unordered_set>
int lengthOfLongestSubstring(std::string s) {
     if (s.empty()) return 0;
     int max_length = 0;
     int start = 0;
     std::unordered_set<char> char_set;
     for (int end = 0; end < s.size(); ++end) {
         while (char_set.find(s[end]) != char_set.end()) {
             char_set.erase(s[start]);
             start++;
         }
        char_set.insert(s[end]);
        max_length = std::max(max_length, end - start + 1);
    }
    return max_length;
}
int main() {
    std::unordered_set<char> char_set = {'a', 'b', 'c', 'd', 'e'};
    for(auto it= char_set.begin(); it != char_set.end(); ++it) {
        std::cout <<*it << " ";
    }
    std::cout << std::endl;

    char_set.insert('a');
    for (auto it=char_set.begin(); it!=char_set.end(); it++) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
    std::string test_str = "abcabcbb";
    int result = lengthOfLongestSubstring(test_str);
    fmt::print("The length of the longest substring without repeating characters in '{}' is: {}\n", test_str, result);
    return 0;
}
